//
//  AppDelegate.m
//  gamebox_qpp
//
//  Created by 赵隆杰 on 2021/12/10.
//

#import "AppDelegate.h"
#import <AuthenticationServices/AuthenticationServices.h>

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    [IQKeyboardManager sharedManager].shouldResignOnTouchOutside = YES;
    
    YTKNetworkConfig *config = [YTKNetworkConfig sharedConfig];
    config.baseUrl = ApiURL;
//    config.baseUrl = @"http://sodom.c14.me:8085";
    config.cdnUrl = @"http://fen.bi";
    
    [[AppLogic sharedInstance] rootControllerSwitchToMainVC];
    
//    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
//    [center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert + UNAuthorizationOptionSound) completionHandler:^(BOOL granted, NSError * _Nullable error) {
//
//    }];
    
    if (@available(iOS 13.0, *)) {
            
            // 注意 存储用户标识信息需要使用钥匙串来存储 这里使用NSUserDefaults 做的简单示例
            NSString * userIdentifier = [[NSUserDefaults standardUserDefaults] valueForKey:@"appleID"];
            
            if (userIdentifier) {
                
                ASAuthorizationAppleIDProvider * appleIDProvider = [[ASAuthorizationAppleIDProvider alloc] init];
                
                [appleIDProvider getCredentialStateForUserID:userIdentifier
                                                  completion:^(ASAuthorizationAppleIDProviderCredentialState credentialState, NSError * _Nullable error) {
                    switch (credentialState) {
                        case ASAuthorizationAppleIDProviderCredentialAuthorized:
                            // 授权状态有效
                            break;
                        case ASAuthorizationAppleIDProviderCredentialRevoked:
                            // 苹果账号登录的凭据已被移除，需解除绑定并重新引导用户使用苹果登录
                            break;
                        case ASAuthorizationAppleIDProviderCredentialNotFound:
                            // 未登录授权，直接弹出登录页面，引导用户登录
                            break;
                        case ASAuthorizationAppleIDProviderCredentialTransferred:
                            // 授权AppleID提供者凭据转移
                            break;
                    }
                }];
            }
        }
    
    return YES;
}

@end
